<template>
  <el-dialog
    title="修改备注"
    :modal="false"
    :visible.sync="centerDialogVisible"
    width="50%"
    center
  >
    <div>
      <el-row :gutter="6">
        <el-form
          ref="paramForm"
          :model="paramData"
          size="mini"
          label-width="280px"
        >
          <el-row>
            <el-col :span="14">
              <el-form-item label="备注" prop="sysRemark">
                <el-input
                  type="textarea"
                  v-model="paramData.sysRemark"
                  placeholder="备注"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="是否发送消息" prop="sendMsg">
                <el-radio-group v-model="paramData.sendMsg">
                  <el-radio :label="0">否</el-radio>
                  <el-radio :label="1">是</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="是否同步到轨迹" prop="synTrace">
                <el-radio-group v-model="paramData.synTrace">
                  <el-radio :label="0">否</el-radio>
                  <el-radio :label="1">是</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="紧急类型" prop="urgencytype">
                <el-select
                  v-model="paramData.urgencytype"
                  placeholder="紧急类型"
                  clearable
                  filterable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(k, v) in urgencytypeOptions"
                    :key="k"
                    :label="urgencytypeOptions[v]"
                    :value="parseInt(v)"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="消息接收人" prop="receiveUserId">
                <el-select
                  v-model="paramData.receiveUserId"
                  multiple
                  placeholder="消息接收人"
                  clearable
                  filterable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(k, v) in userOptions"
                    :key="v"
                    :label="userOptions[v]"
                    :value="parseInt(v)"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-row>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      <el-button
        type="primary"
        @click="saveOrUpdateRemarks"
        v-loading.fullscreen.lock="fullscreenLoading"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { m } from "@/store/yg/common/local";
export default {
  props: {
    userOptions: {
      type: Object,
      default: function(params) {
        return {};
      }
    },
    data: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      fullscreenLoading: false,
      centerDialogVisible: false,
      paramData: {
        id: 0,
        sysRemark: "",
        sendMsg: "0",
        synTrace: "0",
        urgencytype: 0,
        receiveUserId: []
      },
      urgencytypeOptions: {
        0: "红色",
        1: "黄色",
        2: "灰色"
      }
    };
  },

  methods: {
    //修改备注
    saveOrUpdateRemarks() {
      var param = {};
      param["id"] = this.data["id"];
      param["fba"] = 0;
      param["sysRemark"] = this.paramData.sysRemark;
      param["sendMsg"] = this.paramData.sendMsg;
      param["synTrace"] = this.paramData.synTrace;
      param["urgencytype"] = this.paramData.urgencytype;
      param["receiveUserId"] = this.paramData.receiveUserId;
      this.fullscreenLoading = true;
      ajax("editRemarks", param).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code != 200) {
            if (null != res.message) {
              this.$message.error(m(res.message));
            } else {
              this.$message.error("修改失败!");
            }
          } else {
            this.$message.success("修改成功!");
            this.centerDialogVisible = false;
          }
        },
        error => {
          console.log(error);
        }
      );
    }
  },
  mounted() {
    // this.paramData.sysRemark = this.data['sysRemark'];
    this.paramData.sendMsg = this.data["sendMsg"];
    this.paramData.synTrace = this.data["synTrace"];
    if (this.data["urgencytype"]) {
      this.paramData.urgencytype = this.data["urgencytype"];
    }
    this.paramData.receiveUserId = this.data["receiveUserId"];
  }
};
</script>

<style></style>
